package com.zhiche.lisa.bms.controller.psup;


import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.bms.dao.model.psup.PsupOtherExpensises;
import com.zhiche.lisa.bms.pojo.vo.common.CommonVO;
import com.zhiche.lisa.bms.pojo.vo.psup.PsupOtherExpensisesVO;
import com.zhiche.lisa.bms.service.psup.PsupOtherExpensisesService;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 人送其他费用管理 前端控制器
 * </p>
 *
 * @author linbao
 * @since 2019-06-18
 */
@RestController
@RequestMapping("/psupOtherExpensises")
@Api(description = "人送其他费用管理", tags = "人送其他费用管理")
@Slf4j
public class PsupOtherExpensisesController extends PsupSdBaseController {

    @Autowired
    private PsupOtherExpensisesService psupOtherExpensisesService;

    /**
     * 分页查询
     *
     * @return
     */
    @PostMapping(value = "/querySdOtherExpensisesPage")
    @ApiOperation(value = "人送其他费用分页查询", notes = "人送其他费用分页查询", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PsupOtherExpensisesVO.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<PsupOtherExpensisesVO>> querySdOtherExpensisesPage(@RequestBody Page<PsupOtherExpensises> page) {
        log.info("PsupOtherExpensisesController.querySdOtherExpensisesPage param: {}", page);
        RestfulResponse<Page<PsupOtherExpensisesVO>> resultResponse = getSuccessResponse();
        try {
            resultResponse.setData(psupOtherExpensisesService.querySdOtherExpensisesPage(page));
        } catch (BaseException e) {
            log.error("PsupOtherExpensisesController.querySdOtherExpensisesPage error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupOtherExpensisesController.querySdOtherExpensisesPage error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }

    /**
     * 人送其他费用的批量审核
     *
     * @return
     */
    @PostMapping(value = "/auditSdOtherExpensise")
    @ApiOperation(value = "人送基础信息的审核", notes = "人送基础信息的审核", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = RestfulResponse.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Object> auditSdOtherExpensise(@RequestBody CommonVO<Long> commonVO) {
        log.info("PsupOtherExpensisesController.auditSdOtherExpensise param: {}", commonVO);
        RestfulResponse<Object> resultResponse = getSuccessResponse();
        try {
            if (Objects.isNull(commonVO) || CollectionUtils.isEmpty(commonVO.getEntityParams())) {
                throw new BaseException("参数为空, 请选择数据!");
            }
            List<String> resultMst = psupOtherExpensisesService.auditBatchOtherExpensisesByIdList(commonVO.getEntityParams());
            if (CollectionUtils.isNotEmpty(resultMst)) {
                setErrorListResponse(resultResponse, resultMst);
                return resultResponse;
            }
        } catch (BaseException e) {
            log.error("PsupOtherExpensisesController.auditSdOtherExpensise error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupOtherExpensisesController.auditSdOtherExpensise error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }

    /**
     * 人送其他费用的批量删除
     *
     * @return
     */
    @PostMapping(value = "/deleteBatchSdOtherExpensise")
    @ApiOperation(value = "人送其他费用的批量删除", notes = "人送其他费用的批量删除", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = RestfulResponse.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Object> deleteSdOtherExpensise(@RequestBody CommonVO<Long> commonVO) {
        log.info("PsupOtherExpensisesController.deleteBatchSdOtherExpensise param: {}", commonVO);
        RestfulResponse<Object> resultResponse = getSuccessResponse();
        try {
            if (Objects.isNull(commonVO) || CollectionUtils.isEmpty(commonVO.getEntityParams())) {
                throw new BaseException("参数为空, 请选择数据!");
            }
            psupOtherExpensisesService.deleteBatchOtherExpensisesByIdList(commonVO.getEntityParams());
        } catch (BaseException e) {
            log.error("PsupOtherExpensisesController.deleteBatchSdOtherExpensise error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupOtherExpensisesController.deleteBatchSdOtherExpensise error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }
}

